<?php

class BaseView extends ArrayObject {
	public $view = array();
	public $viewdir = '';	
	
	function __construct(){	
		if(!defined('APP_DIR')){
			throw new Exception('not found APP_DIR in BaseView');
			exit();
		}
		$this->viewdir = APP_DIR.'/views/default';
		parent::__construct(array(),ArrayObject::ARRAY_AS_PROPS);
	}
	
	public function render($filename,$output = true){
		ob_start();
		if (file_exists($this->viewdir.'/'.$filename.'.view.php')) {
			require_once($this->viewdir.'/'.$filename.'.view.php');
		}else{
			throw new Exception("not found $filename in".$this->viewdir);
			exit();
		}
		$buffer = ob_get_clean();
		if ($output) {
			echo $buffer;
		} else {
			return $buffer;
		}
	}
	
	public function setScriptPath($filedir){
		$this->viewdir = $filedir;
	}
	
}

?>